<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions">
    <style type="text/css">
        .gridStyle{
            margin:10px 10px 10px 0px;
        }
        .top{
            vertical-align: top;
        }
    </style>
    <h:form>
        <rich:panel header="付款单" id="ipanel" styleClass="content-hight">
            <rich:notifyMessage stayTime="3000"/>

            <h:panelGrid columns="5" id="editGrid0">  
                <h:outputText value="合同编号："/>
                <a4j:commandLink execute="@none" disabled="#{paymentOrderBean.editStatus}"
                                 onclick="#{rich:component('contractPanel')}.show();">
                    <h:inputText value="#{paymentOrderBean.mainInfo.number}" style="margin:5px 0px 5px 3px;"/>
                </a4j:commandLink>
                <a4j:commandButton value="确定" action="#{paymentOrderBean.queryli}"
                                   disabled="#{paymentOrderBean.editStatus}"
                                   execute="@this" render="ipanel"
                                   onclick="this.disabled = 'true';"/>
            </h:panelGrid>

            <rich:toolbar id="tolbar1">
                <rich:toolbarGroup>
                    <a4j:commandButton value="新增"
                                       execute="@this" render="ipanel"
                                       action="#{paymentOrderBean.add}" immediate="true"
                                       disabled="#{empty paymentOrderBean.mainInfo}">
                    </a4j:commandButton>
                    <a4j:commandButton value="修改"
                                       execute="@this" render="ipanel"
                                       action="#{paymentOrderBean.update}"
                                       disabled="#{paymentOrderBean.addOrUpdate
                                                   or empty paymentOrderBean.dataInput
                                                   or empty paymentOrderBean.mainInfo}">
                    </a4j:commandButton>
                    <a4j:commandButton value="保存" render="ipanel"
                                       action="#{paymentOrderBean.checkSave}"
                                       disabled="#{!paymentOrderBean.editStatus}"
                                       onclick="this.disabled = 'true';">
                    </a4j:commandButton>
                    <a4j:commandButton value="删除"
                                       execute="@this" render="ipanel"
                                       action="#{paymentOrderBean.delete}"
                                       disabled="#{paymentOrderBean.addOrUpdate or
                                                   empty paymentOrderBean.mainInfo
                                                   or empty paymentOrderBean.dataInput}">
                    </a4j:commandButton>
                    <a4j:commandButton value="取消"
                                       execute="@this" render="ipanel"
                                       action="#{paymentOrderBean.cancel}"
                                       disabled="#{empty paymentOrderBean.mainInfo}">
                    </a4j:commandButton>
                </rich:toolbarGroup>
            </rich:toolbar>

            <h:panelGrid columns="4" id="editGrid" style="width:60%;">     
                <h:outputText value="合同编号："/>
                <h:inputText value="#{paymentOrderBean.mainInfo.number}" readonly="true"/>

                <h:outputText value="合同名称："/>
                <h:inputText value="#{paymentOrderBean.mainInfo.cname}" readonly="true"/>

                <h:outputText value="合同类别："/>
                <h:inputText value="#{paymentOrderBean.mainInfo.contractTypeName}" readonly="true"/>  

                <h:outputText value="收付款类型："/>
                <h:inputText value="收款" rendered="#{paymentOrderBean.mainInfo.isPayCon eq 0}" readonly="true"/>  
                <h:inputText value="付款" rendered="#{paymentOrderBean.mainInfo.isPayCon eq 1}" readonly="true"/>  
                <h:inputText value="" rendered="#{not(paymentOrderBean.mainInfo.isPayCon eq 0 or paymentOrderBean.mainInfo.isPayCon eq 1)}" readonly="true"/>  

                <h:outputText value="对方单位："/>
                <h:inputText value="#{paymentOrderBean.mainInfo.partner.name}" readonly="true"/>

                <h:outputText value="标的："/>
                <h:inputText value="#{paymentOrderBean.mainInfo.target}" readonly="true"/>
            </h:panelGrid>
            <hr/>
            <h:panelGrid columns="4" id="editGrid1" style="width:80%">       
                <h:outputText value="付款单编号："/>                             
                <h:inputText disabled="#{!paymentOrderBean.editStatus}"
                             readonly="true"
                             value="#{paymentOrderBean.dataInput.orderId}">
                </h:inputText>

                <h:outputText value="付款日期："/>                
                <rich:calendar id="payDate"
                               value="#{paymentOrderBean.dataInput.payTime}"
                               disabled="#{!paymentOrderBean.editStatus
                                           or empty paymentOrderBean.mainInfo}" 
                               locale="zh_CN"
                               required="true"
                               requiredMessage="不能为空！"
                               popup="true"
                               datePattern="yyyy-MM-dd"
                               showApplyButton="false"
                               style="width:200px">
                    <rich:validator/>
                </rich:calendar>

                <h:outputText value="付款金额："/>      
                <h:panelGroup>
                    <h:inputText id="payAmount"
                                 disabled="#{!paymentOrderBean.editStatus}"
                                 value="#{paymentOrderBean.dataInput.amount}" 
                                 required="true" requiredMessage="付款金额不能为空！">
                        <rich:validator/>
                    </h:inputText>

                    <a4j:commandLink id="payPlanButn" value="参照"
                                     disabled="#{!paymentOrderBean.editStatus
                                                 or empty paymentOrderBean.dataInput.number
                                                 or empty paymentOrderBean.mainInfo}"
                                     action="#{paymentOrderBean.showPayPlan}"
                                     execute="@this" render="payPlanGroup"
                                     oncomplete="#{rich:component('payPlanPanel')}.show();"
                                     style="margin-left: 5px;">
                    </a4j:commandLink>
                </h:panelGroup>

                <h:outputText value="备注："/>
                <h:inputText disabled="#{!paymentOrderBean.editStatus
                                         or empty paymentOrderBean.mainInfo}"
                             id="memo"
                             value="#{paymentOrderBean.dataInput.memo}">
                    <f:validateLength maximum="100"/>
                    <rich:validator/>
                </h:inputText>
            </h:panelGrid>
            <hr/>
            <h:panelGroup id="tableGroup">
                <rich:dataScroller for="dataInputinfo" execute="@this" render="tableGroup"/>
                <div style="max-width: 750px;overflow:auto;">
                    <rich:dataTable value="#{paymentOrderBean.dataList}"
                                    var="dataInput"
                                    style="width:100%;margin-bottom: 5px;"
                                    rows="10"
                                    rowKeyVar="rowKey"
                                    id="dataInputinfo"
                                    styleClass="tableStyle"
                                    noDataLabel="无数据！">

                        <f:facet name="header">
                            <h:outputText value="付款单" />
                        </f:facet>

                        <rich:column style="width:50px;text-align:center;">
                            <a4j:commandLink value="选择"
                                             action="#{paymentOrderBean.selected(rowKey)}"
                                             execute="@this"
                                             render="tolbar1,editGrid1"/>
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">
                                <h:panelGroup>
                                    <h:outputText value="付款单编号"/>
                                </h:panelGroup>
                            </f:facet>
                            <h:outputText  value="#{dataInput.orderId}" />
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">
                                <h:panelGroup>
                                    <h:outputText value="付款时间"/>
                                </h:panelGroup>
                            </f:facet>
                            <h:outputText  value="#{dataInput.payTime}">
                                <f:convertDateTime pattern="yyyy年MM月dd日"/>
                            </h:outputText>
                        </rich:column>

                        <rich:column style="text-align:right;">
                            <f:facet name="header">
                                <h:panelGroup>
                                    <h:outputText value="付款金额"/>
                                </h:panelGroup>
                            </f:facet>
                            <h:outputText  value="#{dataInput.amount}"/>
                        </rich:column>

                        <rich:column style="width:200px;">
                            <f:facet name="header">
                                <h:panelGroup>
                                    <h:outputText value="备注"/>
                                </h:panelGroup>
                            </f:facet>
                            <h:outputText title="#{dataInput.memo}" value="#{fn:substring(dataInput.memo,0,30)}"/>
                        </rich:column>

                    </rich:dataTable>
                </div>
            </h:panelGroup>
        </rich:panel>
    </h:form>

    <rich:popupPanel id="contractPanel" autosized="true">
        <f:facet name="header">合同列表</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('contractPanel')}.hide();">关闭</h:outputLink>
        </f:facet>
        <h:form>
            <h:outputLabel  value="合同类型:"/>
            <h:selectOneMenu value="#{paymentOrderBean.type}"
                             style="width:130px;">
                <f:selectItem itemValue="" itemLabel="--请选择--"/>
                <f:selectItem itemValue="0" itemLabel="主合同"/>
                <f:selectItem itemValue="1" itemLabel="补充合同"/>
                <a4j:ajax event="change" render="contractTable"/>
            </h:selectOneMenu>
            <hr/>
            <h:panelGroup id="contractTable">
                <rich:dataScroller for="tableEdit" execute="@this" render="contractTable"/>
                <div style="min-height: 300px;width:750px;overflow: auto;">
                    <rich:dataTable id="tableEdit"
                                    value="#{paymentOrderBean.mainInfoModel}" var="incontract"
                                    rowClasses="list-row-odd,list-row-even"
                                    headerClass="table-header"
                                    rows="6"
                                    style="width:1200px;margin-bottom:5px;"
                                    noDataLabel="无数据">
                        <rich:column sortBy="#{incontract.number}">
                            <f:facet name="header">编号</f:facet>
                            <a4j:commandLink value="#{incontract.number}"
                                             execute="@this" render="ipanel"
                                             action="#{paymentOrderBean.contractSelected}"
                                             onclick="#{rich:component('contractPanel')}.hide();">
                            </a4j:commandLink>
                        </rich:column>
                        <rich:column sortBy="#{incontract.cname}">
                            <f:facet name="header">名称</f:facet>
                            <h:outputText value="#{incontract.cname}">
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.contractTypeName}">
                            <f:facet name="header">合同类别</f:facet>
                            <h:outputText value="#{incontract.contractTypeName}">
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.address}">
                            <f:facet name="header">地点</f:facet>
                            <h:outputText value="#{incontract.address}">
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.orderdate}">
                            <f:facet name="header">签订日期</f:facet>
                            <h:outputText value="#{incontract.orderdate}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.start}">
                            <f:facet name="header">开始日期</f:facet>
                            <h:outputText value="#{incontract.start}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.deadline}">
                            <f:facet name="header">截止日期</f:facet>
                            <h:outputText value="#{incontract.deadline}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.warranty}">
                            <f:facet name="header">质保日期</f:facet>
                            <h:outputText value="#{incontract.warranty}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.nameA}">
                            <f:facet name="header">甲方</f:facet>
                            <h:outputText value="#{incontract.nameA}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.nameAstand}">
                            <f:facet name="header">甲方法人</f:facet>
                            <h:outputText value="#{incontract.nameAstand}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.partner.name}">
                            <f:facet name="header">乙方</f:facet>
                            <h:outputText value="#{incontract.partner.name}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.partner.legalPerson}">
                            <f:facet name="header">乙方法人</f:facet>
                            <h:outputText value="#{incontract.partner.legalPerson}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.target}">
                            <f:facet name="header">标的</f:facet>
                            <h:outputText value="#{incontract.target}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.quality_margin}">
                            <f:facet name="header">质保金</f:facet>
                            <h:outputText value="#{incontract.quality_margin}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.penalty}">
                            <f:facet name="header">违约金</f:facet>
                            <h:outputText value="#{incontract.penalty}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.other}">
                            <f:facet name="header">其他</f:facet>
                            <h:outputText value="#{incontract.other}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.pay}">
                            <f:facet name="header">付款条件</f:facet>
                            <h:outputText value="#{incontract.pay}"/>
                        </rich:column>
                        <f:facet name="footer"></f:facet>
                    </rich:dataTable>

                    <rich:jQuery selector="#tableEdit tr:odd" query="addClass('odd-row')" />
                    <rich:jQuery selector="#tableEdit tr:even" query="addClass('even-row')" />
                    <rich:jQuery selector="#tableEdit tr"
                                 query="mouseover(function(){jQuery(this).addClass('active-row')})"/>
                    <rich:jQuery selector="#tableEdit tr"
                                 query="mouseout(function(){jQuery(this).removeClass('active-row')})"/>
                </div>
            </h:panelGroup>
        </h:form>
    </rich:popupPanel>

    <rich:popupPanel id="payPlanPanel" autosized="true">
        <f:facet name="header">付款计划</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('payPlanPanel')}.hide();">关闭</h:outputLink>
        </f:facet>
        <h:form>
            <h:panelGroup id="payPlanGroup">
                <rich:dataScroller for="detailTable" execute="@this" render="payPlanGroup"/>
                <div style="height:300px;overflow:auto">
                    <rich:dataTable id="detailTable"
                                    value="#{paymentOrderBean.payPlanModel}" var="col"
                                    rowKeyVar="index"
                                    style="width:100%"
                                    noDataLabel="无数据">

                        <rich:column style="text-align:center;width:30px">
                            <a4j:commandLink value="选择"
                                             action="#{paymentOrderBean.payPlanSelect}"
                                             render="payAmount"
                                             onclick="#{rich:component('payPlanPanel')}.hide();">
                            </a4j:commandLink>
                        </rich:column>

                        <rich:column style="text-align: center">
                            <f:facet name="header">行号</f:facet>
                            <h:outputText value="#{index+1}"/>
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">主题</f:facet>
                            <h:outputText  value="#{col.topic}" style="width:95%"/>
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">时间</f:facet>
                            <h:panelGroup>
                                <h:outputText value="#{col.paytime}">
                                    <f:convertDateTime pattern="yyyy年MM月dd日"/>
                                </h:outputText>
                            </h:panelGroup>
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">金额(元)</f:facet>
                            <h:outputText value="#{col.money}"/>
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">备注</f:facet>
                            <h:outputText value="#{detail.memo}"/>
                        </rich:column>
                    </rich:dataTable>
                </div>  
            </h:panelGroup>
        </h:form>
    </rich:popupPanel>
</html>
